<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title></title>
</head>
<body>

<script>
  const data = {
    text: 'hello world!'
  }

  let activeEffect
  const effect = (fn) => {
    activeEffect = fn
    fn()
  }

  const bucket = new Set()

  const obj = new Proxy(data, {
    get(target, key) {
      if (activeEffect) {
        bucket.add(activeEffect)
      }
      return target[key]

    },
    set(target, key, newVal) {
      target[key] = newVal
      bucket.forEach(fn => fn())
      return true
    }
  })

  effect(() => {
    console.log('effect run')
    document.body.innerText = obj.text
  })

  setTimeout(() => {
    obj.text = 'hello vue3!'
    obj.noExist = 'hello vue!'
  }, 1000)
</script>
</body>
</html>
